//
//  BookManager.m
//  03_homework_NSString NSArray NSMutableArray
//
//  Created by dllo on 16/7/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "BookManager.h"

@implementation BookManager

- (instancetype)init {
    self = [super init];
    if (self) {
        _books = [NSMutableArray array];
    }
    return self;
}

- (BOOL)addBook:(Book *)book {
    if (book) {
        [self.books addObject:book];
        return YES;
    }
    return NO;
}

- (BOOL)removebook:(Book *)book {
    [self.books removeObject:book];
    return YES;
}

- (void)list {
    NSLog(@"%@", self.books);
}

- (BOOL)findBookName:(NSString *)bookName changePrice:(double)price {
    for (NSInteger i = 0; i < self.books.count; i++) {
        if ([[self.books[i] name] isEqualToString:bookName]) {
            // self.books[i]是id类型,但是可以接收setPrice:消息.
            [self.books[i] setPrice:price];
            NSLog(@"价格已更改");
            return YES;
        }
    }
    NSLog(@"没有这本书");
    return NO;
}

- (void)listBookName {
    for (Book *book in self.books) {
        NSLog(@"%@", book.name);
    }
}

@end
